import axios from 'axios'
import router from '@/router/index.js'
const instance = axios.create({
  // baseURL:process.env.VUE_APP_URL,
  baseURL: JSON.parse(window.localStorage.getItem('baseUrl')),
  withCredentials: true,
  headers: {
    'X-Requested-With': 'XMLHttpRequest'
  },
  // headers: {
  //   "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
  // }

});
// 请求拦截器
instance.interceptors.request.use(function (config) {
  // console.log(config, "请求拦截器")
  return config;
}, function (error) {
  return Promise.reject(error);
});
// 响应拦截器
instance.interceptors.response.use(function (response) {
  if (response.data.code == 50001) {
    router.push({
      name: 'login'
    })
  }
  return response.data;

}, function (error) {
  router.push({
    name: 'login'
  })
  return Promise.reject(error);
});
export default instance
